<!-- Vue 组件 -->
<template>
  <div>
    <h1>WebSocket Test</h1>
    <textarea v-model="msg" cols="20" rows="3"></textarea>
    <p>
      <button @click="sendMessage">发送</button>
    </p>
    <p>
      <button @click="sendMessage(1)">清空所有客户端的日志</button>
    </p>
    <p>
      <button @click="sendMessage(2)">F5刷新所有的客户端</button>
    </p>
    <!-- <p>Received: {{ receivedMessage }}</p> -->
  </div>
</template>

<script>
import $WS from '@/utils/webSocket.js'

export default {
  data () {
    return {
      queryParams: {},
      msg: 'Hello, server!'
    }
  },
  created () {
    this.queryParams = this.$route.query
    if (!this.queryParams.uuid) {
      const uuid = this.$common.uuid()
      console.log('uuid', uuid)
      this.queryParams.uuid = uuid
      this.$common.setSession('uuid', uuid)
      this.queryParams = this.$common.setHrefParams({ uuid })
    }
    this.msg = this.queryParams.uuid
    // debugger
    this.$socket = $WS.star({ uuid: this.queryParams.uuid })
  },
  methods: {
    // type: 1.清空日志； 2.f5刷新
    sendMessage (type = 0) {
      // console.log('发送')
      this.$socket.dispatch({
        msg: this.msg,
        type: type
      })
    }
  }
}
</script>
